package com.gitee.zycra.future.job.manager;

import com.gitee.zycra.future.job.common.bo.PageQuery;
import com.gitee.zycra.future.job.common.model.JobUser;
import com.gitee.zycra.future.job.common.param.PageQueryUserParam;
import com.gitee.zycra.future.job.common.util.IdGenerator;
import com.gitee.zycra.future.job.dao.JobUserDao;
import com.gitee.zycra.jdbc.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zycra
 */
@Component
public class JobUserManager {

    @Autowired
    private JobUserDao jobUserDao;

    @Autowired
    private IdGenerator idGenerator;

    /**
     * 插入
     *
     * @param jobUser 用户对象
     * @return 插入条数
     */
    public int insertJobUser(JobUser jobUser) {
        jobUser.setId(idGenerator.nextId());
        return jobUserDao.insertJobUser(jobUser);
    }

    /**
     * 禁用/启用
     *
     * @param id      用户ID
     * @param enabled 是否启用
     * @return 影响条数
     */
    public int changeJobUser(Long id, Boolean enabled) {
        return jobUserDao.updateJobUser(new JobUser().setId(id).setEnabled(enabled));
    }

    /**
     * 更新
     *
     * @param jobUser 用户对象
     * @return 更新条数
     */
    public int updateJobUser(JobUser jobUser) {
        return jobUserDao.updateJobUser(jobUser);
    }

    /**
     * 根据用户名查询
     *
     * @param username 用户名
     * @return 查询到的数据
     */
    public JobUser selectJobUserByUsername(String username) {
        return jobUserDao.selectJobUserByUsername(username);
    }

    /**
     * 根据条件查询
     *
     * @param pageQuery 查询条件
     * @return 查询到的数据
     */
    public PageResult<JobUser> selectJobUserForPage(PageQuery<PageQueryUserParam> pageQuery) {
        return jobUserDao.selectJobUserForPage(pageQuery);
    }
}
